import { ApiProperty } from "@nestjs/swagger";
import { $Enums } from "@prisma/client";
import { Transform } from "class-transformer";
import { IsBoolean, IsEnum, IsInt, IsNotEmpty, IsOptional, IsString, Min } from "class-validator";

export class CreateFileDirDto {
    @Transform(({ value }) => Number(value))
    @IsInt()
    // @IsPositive()
    @Min(0, { message: "pid不能小于0" })
    @ApiProperty({ description: "上级菜单ID", example: 1, type: Number, required: true })
    // pid: number = 0; // 设置默认值为 0，表示顶级菜单
    pid: number; // 不能设置默认值，否则当更新其他字段，DTO没传pid时，pid会因默认值而存在DTO中，导致额外更新，以默认值覆盖原pid的值

    @Transform(({ value }) => value.trim())
    @IsString() // 不能过滤空字符串
    @IsNotEmpty()
    @ApiProperty({ description: "目录名称", example: "用户头像", type: String, required: true })
    name: string;

    @IsEnum($Enums.FileType)
    @ApiProperty({
        description: "文件类型: image, video, audio, text, other",
        example: "image",
        type: String,
        required: true
    })
    type: $Enums.FileType;

    @IsInt()
    @Min(0, { message: "状态必须为大于等于0的整数" })
    @ApiProperty({ description: "排序，越大越靠前", example: 0, type: Number, required: true })
    sort: number;

    @IsOptional()
    @IsBoolean()
    @ApiProperty({ description: "是否固定目录", example: false, type: Boolean, required: false })
    isFixed: boolean;

    @IsOptional()
    @IsString()
    @ApiProperty({ description: "备注", example: "用户头像目录", type: String, required: false })
    remark: string;
}
